C# 截取字符串`再急用

来源:百度知道 编辑:UC知道 时间:2024/06/16 07:32:12
仍然不想动脑筋,继续问

比如说, "C:\1\2\3.exe" 我想截取 "C:\1\2\" 该怎么办

string strPath = @"C:\1\2\3.exe";
int itgPostion = strPath.LastIndexOf("\\");
string str1 = strPath.Substring(0, itgPosition);

string str="C:\1\2\3.exe";
string []arr=str.split('.');
arr[0]就是字符串"C:\1\2\"了

string str="C:\1\2\3.exe";
str.Substring(0,7);
str.Substring(0,7);就是你要的字符串。
不过仅限你现在举例的条件下用